package org.zju.demo.utils;

import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Created by admin on 2015/8/26.
 */
public class ApplicationContextUtil implements ServletContextListener {
    private static WebApplicationContext applicationContext = null;

    public ApplicationContextUtil() {
        super();
    }
    public static ApplicationContext getApplicationContext() {
        System.out.println("get webApplicationContext");
        return applicationContext;
    }

    public void contextInitialized(ServletContextEvent servletContextEvent) {
        System.out.println("webApplicationContext");
        applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContextEvent.getServletContext());
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
